import type { App } from 'vue'
import storage from '../storage';
import { message } from 'ant-design-vue';

/**
 * @description 自定义指令
 */
export default {
  install: (Vue: App) => {

    /**
     * @description 复制文本功能
     */
    Vue.directive('copy', {
      mounted(el: HTMLElement, params) {
        const value = params.value;
        el.style.userSelect = 'none';
        el.addEventListener('click', (ev: any) => {
          ev.preventDefault();
          ev.stopPropagation();
          let vDom = document.createElement('input');
          
          document.body.appendChild(vDom);
          vDom.style.opacity = "0";
          vDom.style.position = "position";
          vDom.style.left = "-9999px";
          vDom.value = value;
          vDom.select();
          document.execCommand('copy');
          document.body.removeChild(vDom);
          message.success("复制成功");
        });
      }
    });
  }
}